package com.climber.android.commonres.ui.preview

import android.content.Context
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.climber.android.commonres.ui.BlankFragment
import com.climber.android.commonsdk.helper.newFragment

/**
 * Created by Mikes at 2020-04-17 15:16
 */
internal class MediaPreviewAdapter(val context : Context, fm: FragmentManager, private val previewData: List<MediaPreview>)
    : FragmentPagerAdapter(fm) {

    override fun getCount(): Int = previewData.count()

    override fun getItem(position: Int): Fragment {
        val item = previewData[position]

        return when {
            item.type == MediaPreviewType.PREVIEW_IMAGE -> context.newFragment<MediaImagePreviewFragment>(Pair("mediaPreview", item))
            item.type == MediaPreviewType.PREVIEW_VIDEO -> context.newFragment<MediaVideoPreviewFragment>(Pair("mediaPreview", item))
            else -> BlankFragment()
        }
    }
}